const state = () => ({
  userInfo: JSON.parse(localStorage.getItem('userInfo')) || { token: '', userId: '' }
})
const mutations = {
  setUserInfo (state, userInfo) {
    state.userInfo = userInfo
    localStorage.setItem('userInfo', JSON.stringify(userInfo))
  },
  userLogout (state) {
    localStorage.setItem('userInfo', JSON.stringify({ token: '', userId: '' }))
  }
}

const actions = {}

const getters = {
  // 无法使用计算属性去获取userInfo,如果不通过主模块去调用，仅仅只是js文件而已，还是要从走一遍流程
  getUserInfo (state) {
    return state.userInfo
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions,
  getters
}
